package com.rocket.producer.controller;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;

/**
 * @Description:
 * @ClassName: Producer
 * @Author: mobiusband
 * @Date:2022/11/15 23:22
 * @Version: 1.0
 */
@RestController
public class Producer {
    @Resource
    private RocketMQTemplate rocketMQTemplate;

/**
 * 生产者生产信息，实现简单消息传送
 *
 * @author mobiusband

 * @return java.lang.String
 * @date 2022/11/16 21:58
 */
    @RequestMapping("/push")
    public String get() {
//        发送信息到mytopic主题
        rocketMQTemplate.convertAndSend("mytopic","helloworld" );

        return "生产……";
    }
//    用户注册接口，实现rockemq与redis联动
    @RequestMapping("/newUser")
    public String userReg() {
//        模拟前端接收用户注册信息 user01
        String user01 = "name: jack, id:01, password: 111";
//        发送消息到rocketmq，主题为user，信息为user01
        rocketMQTemplate.convertAndSend("user1", user01 );

        return "用户注册";
    }

}
